package com.wck.car.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wck.car.car.service.AppCarFctService;
import com.wck.car.car.service.AppCarSeriesService;
import com.wck.car.car.service.AppCarTypeService;
import com.wck.car.model.AppCarFct;
import com.wck.car.model.AppCarSeries;
import com.wck.car.model.AppCarType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/car")
public class CarController {

    @Resource
    private AppCarSeriesService appCarSeriesService;

    @Resource
    private AppCarFctService appCarFctService;

    @Resource
    private AppCarTypeService appCarTypeService;

    @GetMapping("/list")
    public List<AppCarSeries> list(@RequestParam String brandId) {
        //根据品牌id查询所有二级品牌id
        List<Object> fctIds = appCarFctService.listObjs(new LambdaQueryWrapper<AppCarFct>().eq(AppCarFct::getBrandid, brandId).select(AppCarFct::getId));

        return appCarSeriesService.list(new LambdaQueryWrapper<AppCarSeries>().in(AppCarSeries::getSeriesId, fctIds));
    }

    @GetMapping("/info")
    public List<AppCarType> info(@RequestParam String seriesId) {
        return appCarTypeService.list(new LambdaQueryWrapper<AppCarType>().eq(AppCarType::getSeriesId, seriesId));
    }
}
